<template>
  <a-dropdown v-if="currentUser && currentUser.empName" placement="bottomRight">
    <span class="ant-pro-account-avatar">
      <a-avatar size="small" icon="user" :src="profilePictureSrc" />
      <span>{{ currentUser.empName }}</span>
    </span>
    <template v-slot:overlay>
      <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
        <!-- <a-menu-item v-if="menu" key="center" @click="handleToCenter">
          <a-icon type="user" />
          个人中心
        </a-menu-item> -->
        <a-menu-item v-if="menu" key="settings" @click="handleToSettings">
          <a-icon type="setting" />
          系统设置
         
        </a-menu-item>
        <a-menu-divider v-if="menu" />
        <a-menu-item key="logout" @click="handleLogout">
          <a-icon type="logout" />
          退出登录
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
  <span v-else>
    <a-spin size="small" :style="{ marginLeft: 8, marginRight: 8 }" />
  </span>
</template>

<script>
import { Modal } from 'ant-design-vue'
import notification from 'ant-design-vue/es/notification'
import defaultSettings from '@/config/defaultSettings'
import storage from 'store'

export default {
  name: 'AvatarDropdown',
  props: {
    
    menu: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      profilePictureSrc:'',
      currentUser:{},
    }
  },
  mounted(){
    this.$nextTick(() => {
      this.currentUser = this.$store.state.user.info
      if(this.currentUser.profilePicture){
        this.profilePictureSrc=defaultSettings.fileServer+"/"+this.currentUser.profilePicture
      }
    })
    
  },
 
  methods: {
    handleToCenter () {
      notification.error({message: '系统提醒',description: '功能开发中',duration:1})
     // this.$router.push({ path: '/404' })
    },
    handleToSettings () {
       this.$emit('handleToSettings');
    //   notification.error({message: '系统提醒',description: '功能开发中',duration:1})
    },
    handleLogout (e) {
      let that = this
      Modal.confirm({
        title: this.$t('layouts.usermenu.dialog.title'),
        content: this.$t('layouts.usermenu.dialog.content'),
        onOk: () => {
         return this.$store.dispatch('Logout').then(() => {
            that.$router.push({ path: '/user/login'})
            location.reload()
          })
         
          
        },
        onCancel () {}
      })
    }
  }
}
</script>

<style lang="less" scoped>
.ant-pro-drop-down {
  /deep/ .action {
    margin-right: 8px;
  }
  /deep/ .ant-dropdown-menu-item {
    min-width: 160px;
  }
}
</style>
